package com.zeroz.routing;

import com.rabbitmq.client.*;
import com.zeroz.utils.ConnectionUtil;

import java.io.IOException;

public class Consumer1 {
    public static void main(String[] args) throws Exception{
        Connection connection = ConnectionUtil.getConnection();
        Channel channel = connection.createChannel();

        String queueName = "test_direct_queue1";
        channel.queueDeclare(queueName, true, false, false, null);

        DefaultConsumer consumer = new DefaultConsumer(channel) {
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.out.println("body："+new String(body));
                System.out.println("Consumer1 将日志信息打印到控制台.....");
            }
        };

        channel.basicConsume(queueName, true, consumer);
    }
}
